----------------------------------Spell Variables--------------------------------------
SPELL.m_iSpellID = 13415 -- Whatever value you want as long as it doesn't override any other spells' IDs.
SPELL.m_iRange = 1024
SPELL.m_sName = "Poison Shot"
SPELL.m_sToolTip =	[[Shoot a poisoned arrow
					at the target, reducing 
					movement speed for 1.5 seconds.]]
SPELL.m_sIcon = "devin/blackbetty/spells/ranger/poisonshot.png"
SPELL.m_iCoolDown = 1.5
SPELL.m_iManaCost = 0
SPELL.m_bRequiresTarget = true
SPELL.m_iSpellType = SPELLTYPE_MAA_AUTOATTACK
SPELL.m_bRecastWhileCasting = false

---------------------------------------------------------------------------------------

function SPELL:Cast( pl, target )
	local weapon = pl:GetWeapon("weapon_all")
	local target = pl:GetNetworkedEntity("Target")
	local range = self.m_iRange
		
	if(target && target:IsValid() && target != pl && target:Health() > 0) then
		pl:EmitSound("devin/blackbetty/weapons/bow/BowRelease01.wav", 80, 100+math.random(-10,10))
		pl:DoAnimationEvent(ACT_HL2MP_GESTURE_RANGE_ATTACK_CROSSBOW)
		-- timer.Simple(0.1, function()
			-- pl:DoAnimationEvent(ACT_HL2MP_GESTURE_RELOAD_AR2)
		-- end)
		hitdelay = ((pl:GetPos() - target:GetPos()):Length()/2400)
		ParticleEffect( "pummel_hit", pl:GetPos() + (pl:GetAngles():Forward()*48) + Vector(0, 0, 45) + (pl:GetAngles():Right()*16), Angle(0,0,0), pl )
		LaunchProjectile(pl, target, 0, "pummel_hit", "", "bindingshot", "devin/blackbetty/weapons/bow/BowArrowInFlightLoop.wav", hitdelay+0.15, 1800, "models/crossbow_bolt.mdl")
		timer.Simple(hitdelay, function()
			self:DealDamage(weapon.MinWeaponDamage*1.2, weapon.MaxWeaponDamage*1.2, pl, target, DMG_GENERIC)
			target:EmitSound("devin/blackbetty/weapons/poison/poison_hit1.wav", 70, 100+math.random(-20,20))
			ParticleEffect( "poisonshot_hit", target:GetPos() + Vector(0, 0, 45), Angle(0,0,0), target )
			if(target:IsPlayer())then
				local b = AddEffect(target, 1, "RangerSlow", 0.85, 0, 1.5, 1)
				b:AddStack()
			end
		end)
	end
end




